package com.pactera.madp.cp.controller.oms.medium;

import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.medium.MediumGroupAddDTO;
import com.pactera.madp.cp.api.dto.medium.MediumGroupUpdateDTO;
import com.pactera.madp.cp.api.vo.medium.MediumGroupVO;
import com.pactera.madp.cp.service.impl.AccountService;
import com.pactera.madp.cp.service.IMediumGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:话术库分组
 * @author: Huayu
 * @time: 2020/12/4 18:42
 */
@RestController
@AllArgsConstructor
@RequestMapping("/mediumgroup")
@Api(value = "mediumgroup", tags = "话术库分组")
public class MediumGroupController {

    @Autowired
    private IMediumGroupService mediumGroupService;

    /**
     * @description:分组列表
     * @return:
     * @author: Huayu
     * @time: 2020/12/7 15:18
     */
    @GetMapping
    @ApiOperation(value = "话术库分组列表")
    public R<List<MediumGroupVO>> mediumGroupIndex(Integer id) {
        return R.ok(mediumGroupService.getMediumGroupList(id));
    }

    /**
     * @description:分组名称修改
     * @return:
     * @author: huhao
     * @time: 2022/6/9 9:57
     */
    @PutMapping("/group-name")
    @ApiOperation(value = "分组名称修改")
    public R<Boolean> updateGroupName(Integer id, String name) {
        return mediumGroupService.updateGroupName(id, name);
    }

    /**
     * @description:话术库分组下是否含有话术检验
     * @return:
     * @author: huhao
     * @time: 2022/6/9 8:45
     */
    @GetMapping("/is-delete")
    @ApiOperation(value = "话术库分组下是否含有话术检验")
    public R<Boolean> isDelete(Integer id) {
        return mediumGroupService.isDelete(id);
    }

    /**
     * @description: 话术库分组添加
     * @return:
     * @author: Huayu
     * @time: 2020/12/7 18:05
     */
    @SysLog("创建话术库分组")
    @PostMapping
    @ApiOperation(value = "创建话术库分组")
    public R<Boolean> mediumGroupStore(@RequestBody MediumGroupAddDTO addDTO) {
        return mediumGroupService.createMediumGroup(addDTO);
    }

    /**
     * @description: 话术库子分组添加
     * @return:
     * @author: huhao
     * @time: 2022/6/9 10:05
     */
    @SysLog("创建话术库子分组")
    @PostMapping("/children")
    @ApiOperation(value = "创建话术库子分组")
    public R<Boolean> saveChildren(Integer id, String name) {
        return mediumGroupService.saveChildren(id, name);
    }

    /**
     * @description: 分组修改
     * @return:
     * @author: Huayu
     * @time: 2020/12/7 18:56
     */
    @SysLog("修改话术库分组")
    @PutMapping
    @ApiOperation(value = "修改话术库分组")
    @ApiImplicitParams({
//            @ApiImplicitParam(name="id",value="话术素材组id"),
//            @ApiImplicitParam(name="name",value="话术素材组名")
    })
    public R<Boolean> mediumGroupUpdate(@RequestBody MediumGroupUpdateDTO dto) {
        Integer corpId = AccountService.getCorpId();
        return mediumGroupService.updateMediumGroupById(corpId, dto);
    }

    /**
     * @description:删除分组
     * @return:
     * @author: Huayu
     * @time: 2020/12/7 19:02
     */
    @SysLog("删除话术库分组")
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除话术库分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="话术素材组id")
    })
    public R<Boolean> mediumGroupDelete(@PathVariable Integer id) {
        return mediumGroupService.deleteMediumGroup(id);
    }

//    /**
//     * @description:根据部门id获取分组
//     * @param id
//     * @return
//     */
//    @GetMapping("/dept")
//    @ApiOperation(value = "根据部门id获取分组")
//    public R<List<MediumGroupVO>> mediumGroupByDept(@RequestParam Integer id){
//        return mediumGroupServiceImpl.getMediumGroupByDept(id);
//    }

}
